home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / asm_subr.arc / TFP2SFP < prev    next >
Encoding:
Text File  |  1985-12-22  |  2.9 KB  |  100 lines

  1. ;-------------------------tfp2sfp routine begins--------------------------+
  2. ; ROUTINE FOR CONVERSION FROM TEMPORARY TO SINGLE PRECISION
  3. ;
  4. ; from BLUEBOOK OF ASSEMBLY ROUTINES FOR IBM PC & XT.
  5. ;         page : 80
  6. ;
  7. ; NAME TFP2SFP
  8. ;
  9. ; FUNCTION: This routine conveerts from temporary binary floating point
  10. ; to single precision floating point.
  11. ;
  12. ; INPUT: Upon entry a number is stored in temporary binary floating point
  13. ; form in FPTEMP1.  The temporary binary floating point number has a 72-bit
  14. ; binary mantissa with 8 bits to the left of those for internal use, a
  15. ; signal byte, and a 16-bit two's complement binary exponent (See fig 5-2).
  16. ;
  17. ; OUTPUT: Upon exit a single precision floating point number is stored in
  18. ; SFPBUFF.  The single precision floating point number has a 24-bit binary
  19. ; mantissa, a sign bit, and an 8-bit exponent biased by 128 (See fig 5-3).
  20. ;
  21. ; REGISTERS USED:  AX and DX are modified.
  22. ;
  23. ; SEGMENTS REFERENCED:  Upon entry the data segment must contain the
  24. ; messages INTERNAL, OVERFLOW and UNDERFLOW, and storage for the temporary
  25. ; binary floating point number FPTEMP1 and the single precision floating
  26. ; point number SFPBUFF.
  27. ;
  28. ; ROUTINES CALLED:  STDSPACE, MESSOUT and HEX16OUT
  29. ;
  30. ; SPECIAL NOTES: Equates are used to shorten address fields.  This is a
  31. ; near procedure needed by FPIN.  Include the file FPCEQU_S at assembly.
  32. ;
  33. ; ROUTINE TO CONVERT FROM TEMP FLOATING POINT TO SINGLE PRECISION
  34. ; FLOATING POINT
  35. ;
  36. tfp2sfp proc    near
  37. ;
  38. ; move mantissa
  39.     mov    ax,fptemp1w4    ; below word
  40.     rcl    ax,1        ; carry for roundup
  41.     mov    ax,fptemp1w6    ; low word
  42.     adc    ax,0        ; low word + carry
  43.     mov    sfpbuffw0,ax    ; put in place
  44.     mov    dx,ax        ; check for zero
  45. ;
  46.     mov    ax,fptemp1w8
  47.     or    dx,ax        ; check this part too
  48.     and    ax,007Fh    ; just bottom 7 bits
  49.     mov    sfpbuffw2,ax    ; put in place
  50. ;
  51. ; move sign bit
  52.     mov    al,fptemp1b10    ; byte 10 is sign
  53.     and    al,80h
  54.     or    sfpbuffb2,al    ; bit 7 is sign
  55. ;
  56. ; move exponent
  57.     mov    ax,fptemp1w11    ; 16-bit two's complement exponent
  58.     cmp    ax,-128        ; too low ?
  59.     jl    ftp2sfp2    ; error message
  60.     cmp    ax,127        ; too high ?
  61.     jg    tfp2sfp3    ; error message
  62. ;
  63.     add    ax,80h        ; bias
  64.     cmp    dx,0        ; was mantissa 0 ?
  65.     jne    tfp2sfp
  66.     mov    al,0        ; then -128 exponent
  67. ;
  68. tfp2sfp1
  69.     mov    sfpbuffb3,al    ; put biased byte back
  70. ;
  71. ; normal return
  72. ;
  73. ; show hex for debugging
  74.     lea    si,internal    ; point to message
  75.     call    stdmessout    ; display message
  76. ;
  77.     mov    dx,sfpbuffw2    ; upper word
  78.     call    hex16out    ; show it
  79. ;
  80.     mov    dx,sfpbuffw0    ; lower word
  81.     call    hex16out    ; show it
  82. ;
  83.     call    stdspace    ; skip a space
  84.     clc
  85.     ret            ; return
  86. ;
  87. ; underflow error
  88. tfp2sfp3:
  89.     lea    si,underflow    ; point to message
  90.     jmp    tfp2sfp4
  91. ;
  92. tfp2sfp4:
  93.     call    stdmessout    ; send message
  94.     stc            ; set carry
  95.     ret            ; return
  96. ;
  97. tfp2sfp    endp
  98. ;-------------------------tfp2sfp routine ends---------------------------+
  99.  
  100.